<template>
  <div class="login">
    <div class="login_top">
      <img src="//award.xmcdn.com/yx/fe-passport/last/dist/images/new-logo-m@2x_2909eca.png" alt="">
    </div>
    <div class="login_content">
      <van-tabs color="#f86442" title-active-color="#f86442" line-width="141px">
     <van-tab title="验证码登录">
      <div class="form_input">
      <div class="form_item flex">
        <label >+ 86 </label>
        <input type="text" placeholder="请输入手机号" v-model="phone">
      </div>
      <button :class="{
        login_input:phone
      }" :disabled="!phone"> 登录</button>
      
      </div>
     </van-tab>
    <van-tab title="密码登录">
      <div class="form_input">
        <div class="form_item flex">
         <label for="">+ 86</label>
         <input type="text" placeholder="请输入手机号" v-model="phone" >
        </div>
        <div class="form_item flex">
          <input type="password" placeholder="请输入密码" v-model="password">
        </div>
        <button :class="{
          login_input:phone && password
        }" :disabled="!(phone && password)" @click="loginHandler">登录</button>
       <div class="email">邮箱登录</div>
      </div>
    </van-tab>
   </van-tabs>


       <div class="radio_wrapper flex">
        <div style="width: 20px;height: 20px;">
        <van-checkbox v-model="checked"   checked-color="#ee0a24" icon-size="14px"></van-checkbox>
      </div>
       <div class="test1">首次登录会自动创建新账号，且代表同意<span>《用户服务协议》</span>和<span>《隐私政策》</span></div>
       </div>

    </div>
    <div class="login_footer">
      <van-divider class="anther" :style="{color:'#999',borderColor:'#ccc'}">其他登录方式</van-divider>
      <div class="test_list flex">
        <van-icon name="qq" size="46" color="#29b4e8"/>
        <van-icon name="weibo" size="46" color="#ec5e5e" />
      </div>
    </div>

  </div>
</template>

<script lang="ts" setup>
import {ref} from 'vue'
import type { AnyObject } from '@/types/category';
import {useRoute,useRouter}from 'vue-router'
import { showToast } from 'vant';
import useUserStore from '@/stores/user';
const userStore=useUserStore()
const route=useRoute()
const router=useRouter()


const phone=ref('')
const password=ref('')
const checked=ref(false)


const loginHandler=async ()=>{

  
  if(!checked.value){
    showToast('请先勾选用户协议')
    return
  }
    let reg=/^1[3-9]\d{9}$/
    if(!reg.test(phone.value)){
      showToast('手机号填写不规范，请重试')
      return
    }
    if(password.value.length <6){
      showToast('密码不能小于6位')
      return
    }

  await userStore.getToken({phone:phone.value,password:password.value})
  
  let path=(route.query.redirect as string)

  if(path){
    router.push(path)
  }else{
    router.push({
      path:'/home'
    })
  }

  }



//获取token

</script>

<style lang="less" scoped>
.login{
  padding: 31px 40px 0px;
  position: relative;
  height: 100%;
  .login_top{
    margin: 0px 0px 20px;
    height: 75px;
    text-align: center;

    img{
      height: 100%;
    }
  }
  .login_content{
    .login_content_top{
      border-bottom: 1px solid #e8e8e8;
      font-size: 20px;
      padding: 10px 0;

    }
    .form_input{
      padding: 16px 0px 0px;
      .form_item{
        margin-top: 20px;
        padding: 14px 0;
        text-align: center;
        align-items: center;
        font-size: 14px;
        border-bottom: 1px solid #E8E8E8;
        label{
          width: 72px;
          border-right: 1px solid #ccc;
        }
        input{
          border: none;
        }
       
      }
      button{
        background: #E8E8E8;
          font-size: 16px;
          color: #fff;
          margin: 20px 0px 0px;
          height: 48px;
          line-height: 48px;
          width: 100%;
          border-radius: 60px;
          border:1px solid #E8E8E8;
        }
        .login_input{
          background: #F86442;
        }
        .email{
          font-size:12px;
          margin: 20px 0px 0px;
        }
    }
    .radio_wrapper{
      
      font-size: 12px;
      margin: 20px 0px 0px;
      .test1{
        color: #999;
        text-align: center;
      overflow: hidden;
      display: -webkit-box; 
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
        margin-left: 3px;
        span{
          color: #F86442;
        }
      }
    }

  }
  .login_footer{
    padding:0px 40px 65px ;
    position: absolute;
    top:600-65px;
    left: 0;
    right: 0;
    text-align: center;
    .anther{
      font-size: 12px;
      margin: 0px 0px 16px;
    }
   
   
    .test_list{
          
          justify-content: space-around;
         
        }
  }

}
</style>